//
//  Node.swift
//  CommandLineTool1
//
//  Created by May on 2025/3/28.
//

import Foundation

/// 单向链表节点
public class ListNode {
    public var val: Int
    public var next: ListNode?
    public init() { self.val = 0; self.next = nil; }
    public init(_ val: Int) { self.val = val; self.next = nil; }
    public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }
}

extension ListNode {
    
    static func PrintList(head: ListNode) {
//        var idx = head
//        while idx != nil {
//            print(idx.val, terminator: "->" )
//            idx = idx.next
//        }
    }
    
    static func GenerateSingleLinkedList(count: Int) -> ListNode? {
//        var head: ListNode = nil
//        var needle: ListNode = nil
//        for idx in 0..<count {
//            let node = ListNode(Int.random(in: 0..<100))
//            if idx == 0 {
//                head = node
//            }
//            needle.next = node
//            needle = node
//        }
//        return head
        return nil
    }
}

/// 双向链表节点
public class Node {
    public var val: Int
    public var prev: Node?
    public var next: Node?
    public var child: Node?
    public init(_ val: Int) {
        self.val = val
        self.prev = nil
        self.next = nil
        self.child  = nil
    }
}

extension Node {
    static func GenerateDoubleLinkedList(count: Int) -> Node {
        return Node(1)
    }
}
